feat: PostgreSQL telemetry backend and consumer header tracking#4
Open
jtalborough wants to merge 1 commit intoRelayPlane:mainfrom
Open
feat: PostgreSQL telemetry backend and consumer header tracking#4jtalborough wants to merge 1 commit intoRelayPlane:mainfrom
jtalborough wants to merge 1 commit intoRelayPlane:mainfrom
Conversation
Add an optional PostgreSQL backend that replaces both JSONL data stores (history.jsonl and telemetry.jsonl) when RELAYPLANE_TELEMETRY_DB is set. When unset, existing JSONL behavior is unchanged. PostgreSQL backend (src/telemetry-pg.ts): - pg.Pool with max 5 connections, auto-creates schema on first connect - Async fire-and-forget writes (errors logged, never thrown to caller) - Rich aggregation queries for dashboard endpoints (by model, consumer) Consumer header tracking: - X-RelayPlane-Consumer header extracted via AsyncLocalStorage (no signature changes to logRequest or sendCloudTelemetry) - Consumer identity stored in request_history and telemetry events - Dashboard /v1/telemetry/runs and /v1/telemetry/stats include consumer - CORS headers updated to allow the new header Also adds pg (^8.13.0) as an optional dependency and @types/pg to devDependencies, plus 13 new tests covering the pg backend.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RELAYPLANE_TELEMETRY_DBis set)X-RelayPlane-Consumerheader support for identifying request sources in multi-client deploymentsAsyncLocalStorage— no function signature changes neededpgadded as optional dependency (dynamic import, graceful fallback)Changes
src/telemetry-pg.ts(new): PostgreSQL backend module with connection pooling, auto-schema creation, fire-and-forget writessrc/telemetry.ts: pg integration inrecordTelemetry(),consumerfield onTelemetryEventsrc/standalone-proxy.ts: AsyncLocalStorage for consumer context, CORS update, pg wiring in history/dashboard endpointspackage.json:pgin optionalDependencies,@types/pgin devDependencies__tests__/telemetry-pg.test.ts(new): 13 tests with mocked pg.PoolHow it works
When
RELAYPLANE_TELEMETRY_DBenv var is set to a PostgreSQL connection string:request_historytable instead ofhistory.jsonlConsumer header:
X-RelayPlane-Consumer: my-serviceto identify themselvesTest plan
npm run buildcompiles cleanlynpm test— 141 pass (1 pre-existing failure in server-sandbox)RELAYPLANE_TELEMETRY_DB, existing JSONL behavior unchanged/v1/telemetry/runsand/v1/telemetry/statsX-RelayPlane-Consumerin allowed headers